﻿#include<iostream>
#include<vector>
#include<algorithm>

class PrintVector
{
public:
	void operator()(int val)
	{
		std::cout << val << ' ';
	}
};

void myPrint(int v)
{
	std::cout << v << " ";
}

class myCompare
{
public:
	bool operator()(int v1, int v2)
	{
		return v1 > v2;
	}
};

void printV(std::vector<int>& v)
{
	for (std::vector<int>::iterator it = v.begin(); it != v.end(); ++it)
	{
		std::cout << *it << " ";
	}
	std::cout << '\n';
}
void test01()
{
	std::vector<int> v1;
	v1.push_back(3);
	v1.push_back(9);
	v1.push_back(7);
	v1.push_back(5);
	v1.push_back(8);
	v1.push_back(2);
	v1.push_back(0);
	v1.push_back(1);

	//1
	for (int i = 0; i < v1.size(); ++i)
	{
		std::cout << v1.at(i) << ' ';
	}
	std::cout << '\n';
	//2
	for (int i = 0; i < v1.size(); ++i)
	{
		std::cout << v1[i] << ' ';
	}
	std::cout << '\n';

	sort(v1.begin(), v1.end());
	//3 函数对象
	std::for_each(v1.begin(), v1.end(), PrintVector());
	std::cout << '\n';
	//4 普通函数
	std::for_each(v1.begin(), v1.end(), myPrint);
	std::cout << '\n';
	//5 迭代器
	sort(v1.begin(), v1.end(), myCompare());
	printV(v1);
}



int main()
{
	test01();


	return 0;
}